// *** LICENSE HEADER ***
// Filename: ./player.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_PLAYER_H
#define NODEWARS_PLAYER_H

#include <SDL.h>
#include <GL/gl.h>
#include "node.h"
#include "nodegraph.h"
#include "lightmanager.h"

class node;
class nodeGraph;
class lightManager;

//Enum of all player types (PT_LOCAL = local player, PT_REMOTE = player from the net)
enum playerType{
    PT_LOCAL,
    PT_REMOTE,
    PT_OTHER
};

//Class, holding the player's data - node graph, color, credits, etc.
class player {
    public:
        player();
        ~player();

        //Reset the player data
        void ResetData();
        //Set the light manager pointer
        void SetLightManager(lightManager* newManager);

        //Change the color of the player
        void SetColor(GLubyte red, GLubyte green, GLubyte blue);
        //Return the color of the player
        SDL_Color GetColor();

        //Add another node to the player's node graph
        node* AddNode(float posX, float posY);
        //Remove a node from the player's node graph
        void RemoveNode(node* toRemove);
        //Return the closest node to a point in 2D from the player's node graph
        node* GetClosestNode(float posX, float posY);

        //Get the currently selected node of the player
        node* GetSelectedNode();
        //Select node closest to the current position
        void SelectNode(float posX, float posY);
        //Deselect selected node
        void DeselectSelected();

        //Add connection between two nodes
        void AddConnection(node* nodeA, node* nodeB);

        //Prepare the player's nodes to receive resources
        void ResetGrowthData();
        //Prepare the player for a new round
        void NewRound();

        //Get/Set credit number
        int GetCredits();
        void SetCredits(int newCredits);
        //Subtract an ammount of credits from the player
        void SubtractCredits(int cost);
        //Add an ammount of credits to the player's account
        void AddCredits(int income);

        //Set/Get the player type
        void SetType(playerType newType);
        playerType GetType();

        //Set the player's player number
        void SetClientNumber(int newClientNumber);
        int GetClientNumber();

        //Find out, whether the player has lost
        bool HasLost();

        //Draw the player's nodes
        void Draw(bool showBoundaries, bool friendly, bool showEnergies);
    private:
        //Pointer to the player's nodes
        nodeGraph* nodes;
        //Pointer to the light manager
        lightManager* theLightManager;
        //Type of the player
        playerType type;
        //Credit number of the player
        int credits;

        //Information for the server (only for PT_REMOTE)
        int clientNumber;

        //Selected node
        node* selected;

        //Color of the player's nodes
        SDL_Color color;
        //has the player lost yet?
        bool lost;
};

#endif
